<%@ page language="java" contentType="text/html; charset=UTF-8"
  pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link href="<%=request.getContextPath()%>/css/base.css" rel="stylesheet" type="text/css" />
<link href="<%=request.getContextPath()%>/css/admin.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="<%=request.getContextPath()%>/js/jquery.min.js"></script>
<script type="text/javascript" src="<%=request.getContextPath()%>/js/jquery.pager.js"></script>
<script type="text/javascript" src="<%=request.getContextPath()%>/js/base.js"></script>
<script type="text/javascript" src="<%=request.getContextPath()%>/js/admin.js"></script>
<script src="<%=request.getContextPath()%>/js/jquery.uploadify.v2.1.4.min.js" type="text/javascript"></script>
<script src="<%=request.getContextPath()%>/js/swfobject.js" type="text/javascript"></script>
<link href="<%=request.getContextPath()%>/js/uploadify.css" rel="stylesheet" type="text/css" />
<title>列表头图片管理</title>
</head>

<BODY class=list><DIV class=bar>列表头图片&nbsp;总记录数: ${fn:length(items)}</DIV>
<DIV class=body>
<c:forEach items="${items}" var="item" varStatus="status">
<DIV>
   <DIV class=info style="float:left;line-height:30px">
     <DIV> ${item.goodsType.typeName}: 链接：<input type="text" id="url${status.index}" style="width:320px" value="${item.firstUrl}"/></DIV>
     <DIV class=img> <img id="img${status.index}" src="<%=request.getContextPath()%>${item.firstImg}" width="300px" height="50px"/></DIV> 
   </DIV>
   <DIV class=edit style="float:left">
       <DT><INPUT hideFocus class=formButton onclick="save(${status.index},${item.id})" value=保存 type=button></DT> 
       <DT><INPUT type="file" class="uploadify" id="upload${status.index}" /> </DT> 
   </DIV>
</DIV>
</c:forEach>
</DIV>
</BODY>

<SCRIPT type=text/javascript><!--
$().ready(function() {	
    for(i=0;i<10;i++)
    {
	//初始化上传按钮
	$("#upload"+i).uploadify( {//初始化函数
    'uploader' :'../js/uploadify.swf',//flash文件位置，注意路径
    'script' :'<%=request.getContextPath()%>/admin/itemUpload.do?sort='+i,//后台处理的请求
    'cancelImg' :'../js/cancel.png',//取消按钮图片
    'folder' :'uploads',//您想将文件保存到的路径
    'queueID' :'fileQueue',//与下面的上传文件列表id对应
    'queueSizeLimit' :1,//上传文件的数量
    'fileDesc' :'jpg、png和gif文件',//上传文件类型说明
    'fileExt' :'*.jpg;*.jpeg;*.png;*.gif', //控制可上传文件的扩展名，启用本项时需同时声明fileDesc
    'method':'post',//如果向后台传输数据，必须是get
    'sizeLimit':10000000,//文件上传的大小限制，单位是字节
    'auto' :true,//是否自动上传
    'multi' :false,
    'simUploadLimit':1,//同时上传文件的数量
    //'buttonText' :'上传',//浏览按钮图片
    'onComplete': function(event, queueID, fileObj,response,data) {//当上传完成后的回调函数
       var data=eval("("+response+")")
       $("#img"+data.sort).attr("src","<%=request.getContextPath()%>"+data.url);
    }
   });	
   }	
})   

function save(index,id)
{
  var imgUrl= $("#url"+index).val();
  var banerimg=$("#img"+index).attr("src");
  var imgName=banerimg.replace('<%=request.getContextPath()%>','');
  var url='<%=request.getContextPath()%>/admin/itemfirstsave.do';
   $.get(url,{imgUrl:imgUrl,imgName:imgName,id:id}, function(result){	
        alert('保存数据成功!');
	  });
}

</SCRIPT>
</html>